﻿using System.Collections;
using UnityEngine;
using UnityEngine.AI;

public class RandomMove : MonoBehaviour
{
	public float radius = 3;
	public float speed = 1;
	public Vector3 origin;
	private float moveTime = 0;
	void Awake()
    {
		origin = transform.position;
	}
	private void Start()
	{
		InitMove();
	}
	void InitMove()
	{
		float x = Random.Range(-radius+ origin.x, radius+ origin.x);
		float z = Random.Range(-radius+ origin.z, radius+ origin.z);
		moveTime = 3;
		GetComponent<CEntity>().searchRadius = radius;
		GetComponent<CEntity>().moveSpeed = speed;
		GetComponent<MoveSystem>().SetDestination(new Vector3(x, 0, z));
	}
    // Update is called once per frame
    void Update()
    {
		moveTime -= Time.deltaTime;
        if(moveTime<= 0)
		{
			InitMove();
		}
    }
}
